package com.lanou3g.sockerPractice;

import com.lanou3g.practice.*;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by dllo on 18/4/21.
 */
public class Client {
    public static void main(String[] args) {


        Socket socket = new Socket(); //创建一个客户端对象

        PrintWriter pw = null;

        Scanner scanner = new Scanner(System.in);
        try {
            socket.connect(new InetSocketAddress("127.0.0.1",7792));

            new ClentReadThread(socket).start();
            OutputStream os = socket.getOutputStream();
            pw = new PrintWriter(new OutputStreamWriter(os));

            while (true){

                String line = scanner.nextLine();
                pw.println(line);
                pw.flush();


            }


        } catch (Exception e) {
            e.printStackTrace();
        }finally {

            IOUtils.closeAll(socket,pw,scanner);


        }


    }



}
